package com.example.demo.dismanage.controller;

import com.example.demo.dismanage.service.DisService;
import com.example.demo.loginmanage.service.LoginService;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Transactional
@CrossOrigin
public class DisController {

    private Logger log = Logger.getLogger(DisController.class);

    @Autowired
    private DisService disService;

    @Autowired
    private LoginService loginService;

    /**
     * @Description 初始化页面，查询所有车辆信息
     * @Author zhangxue
     * @Date 8:53 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/initDisPage",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String initDisPage(@RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(param.size()>=1){
            List<Map<String,Object>> resultList = disService.queryAllCar(param);
            resultMap.put("data",resultList);
            List<Map<String,Object>> resultList1 = disService.queryAllCarManStore(param);
            resultMap.put("data1",resultList1);
            List<Map<String,Object>> resultList2 = loginService.queryAllTrafficInfo(param);
            resultMap.put("data2",resultList2);
        }
        js = JSONObject.fromObject(resultMap);

        return js.toString();
    }

    /**
         * @Description 派车查询司机部门下拉列表
         * @Author zhangxue
         * @Date 10:16 2018/7/31
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryBmByStore",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryBmByStore(@RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(param.size()>=1){
            List<Map<String,Object>> resultList = disService.queryBmByStore(param);
            resultMap.put("data",resultList);
        }else{
            return null;
        }
        js = JSONObject.fromObject(resultMap);

        return js.toString();
    }


    /**
     * @Description 派车查询司机下拉列表
     * @Author zhangxue
     * @Date 10:16 2018/7/31
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryUserByStoreAndBm",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public String queryUserByStoreAndBm(@RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(param.size()>=1){
            List<Map<String,Object>> resultList = disService.queryUserByStoreAndBm(param);
            resultMap.put("data",resultList);
        }else{
            return null;
        }
        js = JSONObject.fromObject(resultMap);

        return js.toString();
    }

    /**
         * @Description 根据条件查询所有车辆信息
         * @Author zhangxue
         * @Date 17:34 2018/7/11
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/yueche",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> yueche(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.yueche(param);
        return statusMap;
    }

    /**
     * @Description 根据ID撤销约车
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/CheYue",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> CheYue(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.CheYue(param);
        return statusMap;
    }

    /**
     * @Description 根据条件查询所有调度信息
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllDoc",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllDoc(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.queryAllDoc(param);
        return statusMap;
    }

    /**
     * @Description 根据条件查询所有约车调度信息
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllDis",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllDis(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.queryAllDis(param);
        return statusMap;
    }

    /**
     * @Description 根据条件查询所有约车调度信息
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllYueDis",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllYueDis(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.queryAllYueDis(param);
        return statusMap;
    }

    /**
     * @Description 删除调度信息
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/delDis",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> delDis(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.delDis(param);
        return statusMap;
    }

    /**
         * @Description 派车
         * @Author zhangxue
         * @Date 11:25 2018/7/31
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/SavePaiInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> SavePaiInfo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.SavePaiInfo(param);
        return statusMap;
    }

    /**
     * @Description 撤销派车为已约车状态
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/delPaiInfo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> delPaiInfo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.delPaiInfo(param);
        return statusMap;
    }

    /**
     * @Description 查询司机任务以及历史记录(phone)
     * @Author zhangxue
     * @Date 17:34 2018/7/11
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/querySjTaskBySjNo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> querySjTaskBySjNo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.querySjTaskBySjNo(param);
        return statusMap;
    }

    /**
         * @Description 查询当前行驶公里数
         * @Author zhangxue
         * @Date 11:23 2018/10/13
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryNowFankilo",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryNowFankilo(@RequestBody Map<String,Object> param){
        Map<String,Object> statusMap = disService.queryNowFankilo(param);
        return statusMap;
    }

}
